package com.nexgo.payment.trans.eclog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.nexgo.oaf.apiv3.emv.EmvCardLogEntity;
import com.nexgo.payment.R;
import com.nexgo.payment.action.ecloglist.EcLogListFragment;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.AbsTransActivity;
import com.nexgo.payment.util.ActivityUtils;

import java.util.List;

/**
 * 电子现金 明细查询
 *
 * Created by wanghongyang on 2017/8/31.
 */
public class EcLogActivity extends AbsTransActivity<EcLogContract.Presenter> implements EcLogContract.View{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new EcLogPresenter(this, Repository.getInstance());
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    public void showEcLogList(List<EmvCardLogEntity> logEntityList) {
        EcLogListFragment logListFragment = EcLogListFragment.newInstance();
        logListFragment.addEcLogList(logEntityList);
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), logListFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), logListFragment, R.id.contentFrame);
        }
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, EcLogActivity.class);
    }
}
